import json

from tornado.web import RequestHandler

class SearchHandler(RequestHandler):
    mapper = {
        'python':'python很火',
        'java':'企业级别20多年语言',
        'H5':'h5全称html5'
    }
    def get(self):
        html = '''
            <h3>搜索%s结果</h3>
            <p>
                %s
            </p>
        '''
        wd = self.get_query_argument('wd')
        result = self.mapper.get(wd)

        resp_data = {
            'wd':wd,
            'result':result
        }
        self.write(json.dumps(resp_data))

        # self.write(html%(wd,result))
        self.set_status(200)
        #设置响应头的数据类型
        self.set_header('Content-Type', 'application/json;charset=utf-8')
        #设置cookie
        self.set_cookie('wd',wd)